﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/BodyMasterPage.Master"
   CodeBehind="wfVarCalculoMnt.aspx.cs" Inherits="RH.wfVarCalculoMnt" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<%@ Import Namespace="Texfina.Core.Common" %>
<%@ Import Namespace="Texfina.Common.Rh" %>
<%@ Import Namespace="Texfina.Common.Mg" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
   <link href="../Styles/jquery-ui.custom.css" rel="stylesheet" type="text/css" />
   <script type="text/javascript">
      window.onload = function () {
         var menuTable = document.getElementById('<%=mnuToolbar.ClientID %>');
         var menuLinks = menuTable.getElementsByTagName("a");
         if (menuLinks != null) {
            switch (menuLinks.length) {
               case 2:
                  menuLinks[0].onclick = function () { return validateEditForm('_BTTSAVE') }
                  break;

               case 3:
                  menuLinks[0].onclick = function () { return validateEditForm('_BTTSAVE') }
                  menuLinks[1].onclick = function () { return validateEditForm('_BTTSAVNEW') }
                  break;
            }
         }

         reloadInPostback();
         this.ResizeGrid();
         this.MessageOnPostback();
      }

      function ResizeGrid() {
         setTimeout(function () {
            var tblMB = document.getElementById('masterMainBar');

            var mnuTb = document.getElementById('mnuToolbar');
            if (mnuTb == null)
               mnuTb = document.getElementById('ContentPlaceHolder1_mnuToolbar');

            var tblEdit = document.getElementById('TableDataHeader');

            var intMBH = 0;
            var intTBH = 0;
            var intEditH = 0;

            if (tblMB)
               intMBH = tblMB.offsetHeight;

            if (mnuTb)
               intTBH = mnuTb.offsetHeight;

            if (tblEdit)
               intEditH = tblEdit.offsetHeight;


            intHDif = $(document).height() - (intEditH + intMBH + intTBH + 220);
            document.getElementById('divTvwValor1').style.height = intHDif + "px";
            document.getElementById('divTvwValor2').style.height = intHDif + "px";
         }, 10);
      }

      function panelOnUpdating() {
         updatePanelAnimationUpdating();
      }

      function panelOnUpdated() {
         reloadInPostback();
         ResizeGrid();
         updatePanelAnimationUpdated();
      }

      function reloadInPostback() {

         var mnuPopupTable = document.getElementById('<%=mnuPopup.ClientID %>');
         var mnuPopupLinks = mnuPopupTable.getElementsByTagName("a");
         if (mnuPopupLinks != null) {
            switch (mnuPopupLinks.length) {
               case 3:
                  mnuPopupLinks[0].onclick = function () { return validateEditFormPopup('_BTTSAVE') }
                  mnuPopupLinks[1].onclick = function () { return validateEditFormPopup('_BTTEVAL') }
                  mnuPopupLinks[2].onclick = function () { return validateEditFormPopup('_BTTEXIT') }
                  break;
            }
         }

         var ctl = document.getElementById('<%=hdnidTipo.ClientID %>');
         var ctlSubCond = document.getElementById('<%=hdnstPerSubCond.ClientID %>');
         var chk = document.getElementById('<%=chkstCondicion.ClientID %>');

         if (ctl.value == '<%=ConstTipoVariable.VARIABLE%>') {
            var varDiv = document.getElementById('divTvwValor1');
            varDiv.style.display = 'none';
            varDiv = document.getElementById('divTvwValor2');
            varDiv.style.display = 'none';

            var varTvw = document.getElementById('<%=tvwstFiltro1.ClientID %>')
            varTvw.style.display = 'none';
            varTvw = document.getElementById('<%=tvwstFiltro2.ClientID %>')
            varTvw.style.display = 'none';
         }

         if (ctlSubCond.value == '<%=ConstFlagEstado.DESACTIVADO%>') {
            $('#<%=rbStCondic1.ClientID%>').attr('disabled', 'disabled');
            $('#<%=rbStValor1.ClientID%>').attr('disabled', 'disabled');
            document.getElementById('<%=txtnuValor1.ClientID %>').disabled = true;
            document.getElementById('<%=btnDsCondic1.ClientID %>').disabled = true;

            $('#<%=rbStCondic2.ClientID%>').attr('disabled', 'disabled');
            $('#<%=rbStValor2.ClientID%>').attr('disabled', 'disabled');
            document.getElementById('<%=txtnuValor2.ClientID %>').disabled = true;
            document.getElementById('<%=btnDsCondic2.ClientID %>').disabled = true;
            document.getElementById('<%=tvwstFiltro2.ClientID %>').disabled = true;
         }

         if (!chk.checked) {
            $('#<%=rbStCondic2.ClientID%>').attr('disabled', 'disabled');
            $('#<%=rbStValor2.ClientID%>').attr('disabled', 'disabled');
            document.getElementById('<%=txtnuValor2.ClientID %>').disabled = true;
            document.getElementById('<%=btnDsCondic2.ClientID %>').disabled = true;
            document.getElementById('<%=tvwstFiltro2.ClientID %>').disabled = true;
         }
         else {
            document.getElementById('<%=bttDsCondicion.ClientID %>').disabled = false;
         }

      }
   </script>
   <style type="text/css">
      .esdbuttonFunction
      {
         background: url('../Images/Icons/Enabled/function.png');
         border: none;
         width: 21px;
         height: 22px;
         position: absolute;
      }
      .esdbuttonFunction:hover
      {
         cursor: pointer;
      }
      .esdTreeview
      {
         border: 1px solid #cccccc;
      }
      .esdTreeview
      {
         width: 100%;
         overflow: auto;
         border: 1px solid #cccccc;
      }
   </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
   <div class="ToolBar">
      <asp:Menu ID="mnuToolbar" runat="server" CssClass="ToolBarControl" Orientation="Horizontal"
         OnMenuItemClick="mnuToolbar_MenuItemClick">
         <Items>
            <asp:MenuItem Text="Guardar" Value="_BTTSAVE" ImageUrl="../Images/Icons/Enabled/SAVE.png">
            </asp:MenuItem>
            <asp:MenuItem Text="Salir" Value="_BTTEXIT" ImageUrl="../Images/Icons/Enabled/BACK.png">
            </asp:MenuItem>
         </Items>
      </asp:Menu>
   </div>
   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
         <div class="DataHeader">
            <table id="TableDataHeader" cellpadding="0" cellspacing="0">
               <tr>
                  <td colspan="3">
                     &nbsp;
                  </td>
               </tr>
               <tr>
                  <td style="width: 5px">
                     &nbsp;
                  </td>
                  <td>
                     <div style="border: 1px solid #ccc; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                        -ms-border-radius: 5px;">
                        <table width="100%" cellpadding="0" cellspacing="2">
                           <tr>
                              <td colspan="13">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                              <td style="width: 110px;">
                                 Codigo
                              </td>
                              <td colspan="10">
                                 <esd:esdTextBox runat="server" ID="txtidVarCalc" Width="180px" MaxLength="15"></esd:esdTextBox>
                              </td>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                              <td>
                                 Descripcion
                              </td>
                              <td colspan="10">
                                 <esd:esdTextBox runat="server" ID="txtdsValCalc" Width="480px"></esd:esdTextBox>
                              </td>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr valign="middle">
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                              <td>
                                 <asp:CheckBox ID="chkstCondicion" runat="server" Text="Condicional" />
                              </td>
                              <td colspan="9">
                                 <esd:esdTextBox runat="server" ID="txtdsCondicion" TextMode="MultiLine" Height="38px"
                                    Width="480px"></esd:esdTextBox>
                                 <asp:Button ID="bttDsCondicion" CssClass="esdbuttonFunction" runat="server" OnClick="bttDsCondicion_Click" />
                              </td>
                              <td>
                              </td>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td colspan="13">
                                 &nbsp;
                              </td>
                           </tr>
                        </table>
                     </div>
                  </td>
                  <td style="width: 5px">
                     &nbsp;
                  </td>
               </tr>
               <tr>
                  <td colspan="3">
                     &nbsp;
                  </td>
               </tr>
            </table>
         </div>
         <div class="DataDetail">
            <table width="100%" cellpadding="0" cellspacing="0">
               <tr>
                  <td style="width: 5px;">
                     &nbsp;
                  </td>
                  <td>
                     <div id="divDataDetail" style="border: 1px solid #ccc; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
                        -ms-border-radius: 5px;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                           <tr>
                              <td colspan="13">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                              <td>
                                 &nbsp;
                              </td>
                              <td>
                                 Tabla
                              </td>
                              <td>
                                 <asp:DropDownList ID="ddlidTabla" runat="server" Width="180px" AutoPostBack="True"
                                    OnSelectedIndexChanged="ddlidTabla_SelectedIndexChanged">
                                 </asp:DropDownList>
                              </td>
                              <td style="width: 15px">
                                 &nbsp;
                              </td>
                              <td>
                                 Funcion
                              </td>
                              <td colspan="2">
                                 <asp:DropDownList ID="ddlidAcumula" runat="server" Width="180px" AutoPostBack="True"
                                    OnSelectedIndexChanged="ddlidAcumula_SelectedIndexChanged">
                                 </asp:DropDownList>
                              </td>
                              <td style="width: 15px">
                                 &nbsp;
                              </td>
                              <td>
                                 Columna
                              </td>
                              <td colspan="2">
                                 <asp:DropDownList ID="ddlidColumn" runat="server" Width="180px">
                                 </asp:DropDownList>
                              </td>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td colspan="13">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                              <td colspan="11">
                                 <ajax:TabContainer ID="tabMaster" ScrollBars="Auto" runat="server" CssClass="gray"
                                    Width="100%" ActiveTabIndex="0">
                                    <ajax:TabPanel ID="tabValor1" runat="server" HeaderText="Condicion Verdadero">
                                       <contenttemplate>
                                       <table width="100%" cellpadding="0" cellspacing="2">
                                         <tr>
                                             <td colspan="13">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td style="width: 85px">
                                                <asp:RadioButton runat="server" ID="rbStCondic1"
                                                   GroupName="grpCondiValor" Text="Condicion"/>
                                              </td>
                                             <td style="width: 85px">
                                                <asp:RadioButton runat="server" ID="rbStValor1" GroupName="grpCondiValor" Checked="True" Text="Valor"/>
                                              </td>
                                             <td colspan="9">
                                                <esd:esdNumericTextBox ID="txtnuValor1" runat="server" NumericType="Decimal" Width="120px"></esd:esdNumericTextBox>
                                                </td>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td colspan="11">
                                                <esd:esdTextBox ID="txtdsCondic1" runat="server" TextMode="MultiLine" Width="95%" Height="38px"></esd:esdTextBox>
                                                <asp:Button ID="btnDsCondic1" CssClass="esdbuttonFunction" runat="server" 
                                                   onclick="btnDsCondic1_Click" />
                                             </td>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td colspan="13">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td colspan="11">
                                               <div id="divTvwValor1" class="esdTreeview">
                                               <asp:TreeView ID="tvwstFiltro1" runat="server" Width="100%" Height="100px"
                                                 NodeIndent="15" ShowCheckBoxes="Leaf">
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />

<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" 
                                                    HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />

<ParentNodeStyle Font-Bold="False" />

<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" 
                                                    HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>



                                               </div>
                                             </td>   
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td colspan="3">
                                                &nbsp;
                                             </td>
                                          </tr>
                                       </table>
                                    
</contenttemplate>
                                    </ajax:TabPanel>
                                    <ajax:TabPanel ID="tabValor2" runat="server" HeaderText="Condicion Falso">
                                       <contenttemplate>
                                       <table width="100%" cellpadding="0" cellspacing="2">
                                         <tr>
                                             <td colspan="13">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td style="width: 85px">
                                                <asp:RadioButton runat="server" ID="rbStCondic2" GroupName="grpCondiValor" Text="Condicion"/>
                                              </td>
                                             <td style="width: 85px">
                                                <asp:RadioButton runat="server" ID="rbStValor2" GroupName="grpCondiValor"  Checked="True" Text="Valor"/>
                                              </td>
                                             <td colspan="9">
                                                <esd:esdNumericTextBox ID="txtnuValor2" runat="server" NumericType="Decimal" Width="120px"></esd:esdNumericTextBox>
                                                </td>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td colspan="11">
                                                <esd:esdTextBox ID="txtdsCondic2" runat="server" TextMode="MultiLine" Width="95%" Height="38px"></esd:esdTextBox>
                                                <asp:Button ID="btnDsCondic2" CssClass="esdbuttonFunction" runat="server" />
                                             </td>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td colspan="13">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                             <td colspan="11">
                                               <div id="divTvwValor2" class="esdTreeview">
                                               <asp:TreeView ID="tvwstFiltro2" runat="server" Width="100%" Height="100px"
                                                 NodeIndent="15" ShowCheckBoxes="Leaf">
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />

<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" 
                                                    HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />

<ParentNodeStyle Font-Bold="False" />

<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" 
                                                    HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>



                                               </div>
                                             </td>   
                                             <td style="width: 5px">
                                                &nbsp;
                                             </td>
                                          </tr>
                                          <tr>
                                             <td colspan="3">
                                                &nbsp;
                                             </td>
                                          </tr>
                                       </table>
                                    
</contenttemplate>
                                    </ajax:TabPanel>
                                 </ajax:TabContainer>
                              </td>
                              <td style="width: 5px">
                                 &nbsp;
                              </td>
                           </tr>
                           <tr>
                              <td colspan="3">
                                 &nbsp;
                              </td>
                           </tr>
                        </table>
                     </div>
                  </td>
                  <td style="width: 5px;">
                     &nbsp;
                  </td>
               </tr>
            </table>
         </div>
         <asp:HiddenField ID="hdnMsgOPB" runat="server" />
         <asp:HiddenField ID="hdnidConRemu" runat="server" />
         <asp:HiddenField ID="hdnidTipo" runat="server" />
         <asp:HiddenField ID="hdnstPerSubCond" runat="server" Value="1" />
         <asp:Panel runat="server" ID="PnlPopup" CssClass="modalPopup" Width="600px" Style="display: none">
            <table width="100%" cellpadding="0" cellspacing="0">
               <tr>
                  <td colspan="3">
                     <div class="modalPopupHeader">
                        &nbsp;&nbsp;&nbsp;<asp:Label ID="lblTitlePopup" runat="server"></asp:Label>
                     </div>
                  </td>
               </tr>
               <tr>
                  <td colspan="3">
                     <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                           <td colspan="13">
                              <div class="ToolBarGrid" style="border-left-width: 0; border-right-width: 0;">
                                 <asp:Menu ID="mnuPopup" runat="server" Orientation="Horizontal" CssClass="ToolBarControl"
                                    OnMenuItemClick="mnuPopup_MenuItemClick">
                                    <Items>
                                       <asp:MenuItem Text="  Guardar y Cerrar" Value="_BTTSAVE" ImageUrl="../Images/Icons/Enabled/SAVE.png">
                                       </asp:MenuItem>
                                       <asp:MenuItem Text="  Evaluar" Value="_BTTEVAL" ImageUrl="../Images/Icons/Enabled/Check.png">
                                       </asp:MenuItem>
                                       <asp:MenuItem Text="  Salir" Value="_BTTEXIT" ImageUrl="../Images/Icons/Enabled/BACK.png">
                                       </asp:MenuItem>
                                    </Items>
                                 </asp:Menu>
                              </div>
                           </td>
                        </tr>
                        <tr>
                           <td style="width: 5px">
                              &nbsp;
                           </td>
                           <td colspan="5">
                              <div style="height: 370px; overflow: auto; border: 1px solid #cccccc; width: 230px;">
                                 <asp:TreeView ID="tvwCampoFor" runat="server" Width="210px" Height="100px" NodeIndent="15">
                                    <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                                    <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
                                       NodeSpacing="0px" VerticalPadding="2px" />
                                    <ParentNodeStyle Font-Bold="False" />
                                    <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
                                       VerticalPadding="0px" />
                                 </asp:TreeView>
                              </div>
                           </td>
                           <td colspan="6">
                              <table width="100%" cellpadding="0" cellspacing="0">
                                 <tr>
                                    <td style="text-align: center; background: #000000 0 -2600px repeat-x url('../Images/Controls/sprite.gif');">
                                       Formula
                                    </td>
                                 </tr>
                                 <tr>
                                    <td>
                                       <esd:esdTextBox ID="txtdsFormula" runat="server" Width="354px" Height="355px" TextMode="MultiLine"></esd:esdTextBox>
                                    </td>
                                 </tr>
                              </table>
                           </td>
                           <td style="width: 5px">
                              &nbsp;
                           </td>
                        </tr>
                     </table>
                  </td>
               </tr>
               <tr>
                  <td colspan="3">
                     &nbsp;
                  </td>
               </tr>
            </table>
         </asp:Panel>
         <ajax:ModalPopupExtender runat="server" ID="mdlPopup" PopupControlID="PnlPopup" BackgroundCssClass="modalBackground"
            TargetControlID="hdnidConRemu">
         </ajax:ModalPopupExtender>
      </ContentTemplate>
   </asp:UpdatePanel>
   <ajax:UpdatePanelAnimationExtender ID="upae" BehaviorID="animation" runat="server"
      TargetControlID="updatePanel1">
      <animations>
        <OnUpdating>
        <Parallel duration="0.5">
            <ScriptAction Script="panelOnUpdating();" />  
        </Parallel>
        </OnUpdating>
        <OnUpdated>
        <Parallel duration="0.5">
            <ScriptAction Script="panelOnUpdated();" /> 
        </Parallel> 
        </OnUpdated>
    </animations>
   </ajax:UpdatePanelAnimationExtender>
   <div id="updateProgressDiv" class="updateProgress" style="display: none">
      <table width="100%">
         <tr>
            <td valign="middle">
               <img src="../Images/Controls/Loading.gif" />
            </td>
            <td valign="middle">
               <span class="updateProgressMessage">Cargando ...</span>
            </td>
         </tr>
      </table>
   </div>
</asp:Content>
